package com.wanmait.wanmarecruit.webController;

import com.wanmait.wanmarecruit.entity.Company;
import com.wanmait.wanmarecruit.entity.CompanySize;
import com.wanmait.wanmarecruit.entity.Position;
import com.wanmait.wanmarecruit.entity.User;
import com.wanmait.wanmarecruit.service.ProvinceService;
import com.wanmait.wanmarecruit.service.UserService;
import com.wanmait.wanmarecruit.service.*;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Controller
@RequestMapping("web")
public class WebCommonController {

    @Resource
    private PositionTypeSecondService positionTypeSecondService;
    @Resource
    private WorkExperienceTypeService workExperienceTypeService;
    @Resource
    private EducationService educationService;
    @Resource
    private ProvinceService provinceService;
    @Resource
    private UserService userService;
    @Resource
    private JobStatusService jobStatusService;
    @Resource
    private TechnologyService technologyService;
    @Resource
    private WorkExperienceService workExperienceService;
    @Resource
    private PositionTypeService positionTypeService;
    @Resource
    private EducationExperienceService educationExperienceService;
    @Resource
    private StudentCadreExperienceService studentCadreExperienceService;
    @Resource
    private HonorsWonService honorsWonService;
    @Resource
    private JobOrientationService jobOrientationService;
    @Resource
    private CompanyNatureService companyNatureService;
    @Resource
    private CompanySizeService companySizeService;
    @Resource
    private CompanyService companyService;
    @Resource
    private SalaryService salaryService;
    @Resource
    private WelfareService welfareService;
    @Resource
    private IntroductionTabService introductionTabService;
    @Resource
    private NoticeService noticeService;
    @Resource
    private PositionService positionService;
    @Resource
    private ConfigService configService;
    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    //企业邮箱认证
    @RequestMapping("/companies/companySignUpAuthentications")
    public void companySignUpAuthentications(){

    }

    //企业邮箱认证
    @RequestMapping("/companies/companySignUpAuthentication")
    public void companySignUpAuthentication(){

    }

    //填写企业个人认证信息
    @RequestMapping("/companies/companySignUpRecruiterInfo")
    @ModelAttribute("companies")
    public List<Company> companySignUpRecruiterInfo(){
        return companyService.list();
    }

    //企业注册头
    @RequestMapping("/companies/inc/companySignUpHead")
    public void companySignUpHead(){

    }

    //公司登录忘记密码
    @RequestMapping("/companies/companyForgetPass")
    public void companyForgetPass(){

    }

    //公司密码登录
    @RequestMapping("/companies/companyLogin")
    public void companyLogin(){

    }

    //公司注册
    @RequestMapping("/companies/companySignUp")
    public void companySignUp(){

    }

    //公司登录
    @RequestMapping("/companies/companySignIn")
    public void companySignIn(){

    }

    //修改密码
    @RequestMapping("/personal/forgetPass")
    public void forgetPass(){

    }

    //企业头
    @RequestMapping("/companies/inc/companyHead")
    public void companyHead(){

    }

    //企业脚
    @RequestMapping("/companies/inc/companyFoot")
    public void companyFoot(){

    }

    //发布新职位
    @RequestMapping("/companies/publishNewPosition")
    public ModelAndView publishNewPosition(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("introductionTabs",introductionTabService.getAllIntroductionTab());
        modelAndView.addObject("welfares",welfareService.getAllWelfare());
        modelAndView.addObject("provinces",provinceService.getAllProvinces());
        modelAndView.addObject("educations",educationService.getAllEducation());
        modelAndView.addObject("workExperienceTypes",workExperienceTypeService.getAllWorkExperience());
        modelAndView.addObject("positionTypes",positionTypeService.getAllPositionType());
        modelAndView.addObject("positionTypeSeconds",positionTypeSecondService.getAllPositionTypeSecond());
        modelAndView.addObject("salarys",salaryService.getAllSalary());
        modelAndView.setViewName("/web/companies/publishNewPosition");
        return modelAndView;
    }

    //公司职位管理
    @RequestMapping("companies/companyPosition")
    public void companyPosition(){

    }

    @RequestMapping("companies/companyPositionData")
    public ModelAndView companyPositionData(HttpSession session, Position position,Integer pageNum){
//        Integer companyId = ((Company) session.getAttribute("company")).getId();
        Integer companyId = 2;
        Integer pageSize = Integer.parseInt(configService.getByKeyword("position_paging_size").getConfigValue());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("positions",positionService.getPosition(position,companyId,pageNum,pageSize));
        return modelAndView;
    }

    //短信验证
    @RequestMapping("/personal/smsVerify")
    public void smsVerify(){

    }

    //注册
    @RequestMapping("/personal/signUp")
    public void signUp(){

    }

    //注册头
    @RequestMapping("/personal/inc/personalSignUpHead")
    public void personalSignUpHead(){

    }

    //注册脚
    @RequestMapping("/personal/inc/personalSignUpFoot")
    public void personalSignUpFoot(){

    }

    //登录
    @RequestMapping("/personal/signIn")
    public void signIn(){

    }

    //简历
    @RequestMapping("/personal/curriculumVitae")
    public ModelAndView curriculumVitae(HttpSession session)
    {
        User user = (User)session.getAttribute("user");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user",userService.getById(user.getId()));
        modelAndView.addObject("provinces",provinceService.getProvincesBySort());
        modelAndView.addObject("jobStatuses",jobStatusService.list());
        modelAndView.addObject("technologies",technologyService.getTecByUser(user.getId()));
        modelAndView.addObject("workExperiences",workExperienceService.getWorkExperienceByUser(user.getId()));
        modelAndView.addObject("positionTypes",positionTypeService.list());
        modelAndView.addObject("educationExperiences",educationExperienceService.getEducationByUser(user.getId()));
        modelAndView.addObject("studentCadreExperiences",studentCadreExperienceService.getCadreByUserId(user.getId()));
        modelAndView.addObject("honorsWons",honorsWonService.getHonorsByUserId(user.getId()));
        modelAndView.addObject("jobOrientations",jobOrientationService.getJobOrientationByUserId(user.getId()));
        modelAndView.addObject("salaries",salaryService.list());
        modelAndView.addObject("notices",noticeService.selectAllNoticeByUser(user.getId(),1,10));
        modelAndView.addObject("numOfNotice",noticeService.getAllNoticeNotRead(user.getId()));
        return modelAndView;
    }

     //于晓菲
    @RequestMapping("/personal/personalCenter")
    public void personalCenter()
    {

    }
    @RequestMapping("/personal/inc/personalCenterHead")
    public ModelAndView personalCenterHead(HttpSession session)
    {
        Integer userId = ((User)session.getAttribute("user")).getId();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("notices",noticeService.selectAllNoticeByUser(userId,1,10));
        modelAndView.addObject("numOfNotice",noticeService.getAllNoticeNotRead(userId));
        return modelAndView;
    }

    @RequestMapping("/personal/companyList")
    public ModelAndView companyList()
    {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("positionTypes",positionTypeService.list());
        modelAndView.addObject("companyNatures",companyNatureService.list());
        List<CompanySize> companySizes = companySizeService.list();
        companySizes.forEach(companySize -> {
            companySize.setCompanyCount(companyService.getCountByCompanySize(companySize.getId()));
        });
        modelAndView.addObject("companySizes",companySizes);
        return modelAndView;
    }

    @RequestMapping("/personal/login")
    public void login()
    {

    }

    @RequestMapping("/companies/companySignUpChooseCompanyOrNot")
    public void companySignUpChooseCompanyOrNot()
    {

    }

}
